package com.hyh.toyshopping.controller;

import com.hyh.toyshopping.commons.CurUser;
import com.hyh.toyshopping.commons.Result;
import com.hyh.toyshopping.model.Car;
import com.hyh.toyshopping.model.view.CarView;
import com.hyh.toyshopping.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @version 1.0
 * @BelongsProject:IntelliJ IDEA
 * @BelongsPackage:com.hyh.toyshopping.controller
 * @Author:hyhWTX
 * @ClassName:CarController
 * @CreateTime:2022年-12月-15日 12:52
 * @Description: TODO (一句话描述以下该类的功能)
 */
@RestController
@RequestMapping("/car")
public class CarController {
    @Autowired
    private CarService carService;
    @RequestMapping("/addCar")
    public Result addCar(@RequestBody Car car){
        carService.addCar(car);
        return Result.success("购物车添加成功！");
    }
    @GetMapping("/getCount")
    public Integer getCount(int user_id){
        return carService.getCount(user_id);
    }
    @RequestMapping("/updateCar")
    public Result update(@RequestBody Car car){
        carService.updateCarCount(car);
        return  Result.success();
    }

    @GetMapping("/getCarList")
    public List<CarView> getCarList(HttpSession session){
        //从session中获取用户编号
        CurUser curUser = (CurUser) session.getAttribute("curUser");
        return  carService.getCarList(curUser.getUser_id());
    }

    @DeleteMapping("/deleteCar")
    public Result deleteCar(int car_id){
        carService.deleteCar(car_id);
        return Result.success();
    }
    /***
     * @Description: 根据购物车编号获得购物车中的商品信息
     * @param car_ids
     * @return List<CarView>

     */

    @RequestMapping("/getPayCarList")
    public List<CarView> getPayCarList(int[] car_ids){
        return  carService.getPayCarList(car_ids);
    }
}
